#include <iostream>
#include <vector>
using namespace std;

class Solution {
public:
    int minOperations(vector<int>& nums, int x) {
        int left = 0, right = 0;
        int n = nums.size();
        int len = -1;
        int sum = 0;

        for (int i = 0; i < n; i++)
        {
            sum += nums[i];
        }
        int target = sum - x;
        if (target < 0) return -1;
        sum = 0;
        while (right < n)
        {
            sum += nums[right];
            while (sum > target)
            {
                sum -= nums[left++];
            }
            if (sum == target)
            {
                len = max(len, right - left + 1);
            }
            right++;
        }
        return len == -1 ? len : n - len;
    }
};


int main()
{
    vector<int> v1 = { 8828,9581,49,9818,9974,9869,9991,10000,10000,10000,9999,9993,9904,8819,1231,6309 };
    Solution S1;
    int index = S1.minOperations(v1, 134365);
    return 0;
}